package com.zl.tby.core.base.util;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

/**
 * @author changpeng
 * @version 1.0
 * @since 2024/11/6 19:17
 */
public class SimpleSocketClient {
    public static void main(String[] args) {
        List<String> dataList = new ArrayList<>();
        dataList.add("#0112030C24110815110000AB00000000000000000000049602C30000000000000000000023360000000000000000000000000001014C00050006000700000000000000000000000000000000000300000000000000000000000000000000001E0000007E001400160000156AGG");

        for (String s : dataList) {
            try {
                Socket clientSocket = new Socket("127.0.0.1", 9001);
                PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
                BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
                // 发送数据到服务器
                out.println(s);
                // 读取服务器响应
                String response;
                while ((response = in.readLine()) != null) {
                    System.out.println("Server replied: " + response);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }
}
